package cn.iocoder.yudao.module.reading.dal.mysql.community;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.reading.dal.dataobject.community.CommunityWorkCollectionDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 社区作品收藏 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface CommunityWorkCollectionMapper extends BaseMapperX<CommunityWorkCollectionDO> {

    /**
     * 查询用户对指定作品的收藏记录
     */
    default CommunityWorkCollectionDO selectByUserIdAndWork(Long userId, Long workId, String workType) {
        return selectOne(CommunityWorkCollectionDO::getUserId, userId,
                        CommunityWorkCollectionDO::getWorkId, workId,
                        CommunityWorkCollectionDO::getWorkType, workType);
    }

    /**
     * 统计作品的收藏数
     */
    default Long countByWork(Long workId, String workType) {
        return selectCount(new LambdaQueryWrapperX<CommunityWorkCollectionDO>()
                .eq(CommunityWorkCollectionDO::getWorkId, workId)
                .eq(CommunityWorkCollectionDO::getWorkType, workType));
    }

}
